package com.ptit.piclient.tools;

import com.ptit.piclient.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
 
public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
     
    public ImageAdapter(Context c) {
        mContext = c;
        mInflater = LayoutInflater.from(mContext);
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        
        ViewHolder holder;
        if (convertView == null) {             
           convertView = mInflater.inflate(R.layout.grid_row_view, null);
           holder = new ViewHolder();
           holder.ImgThumb = (ImageView) convertView.findViewById(R.id.imgThumb);
           holder.ImhText  = (TextView) convertView.findViewById(R.id.imgText);            
           convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
         
        holder.ImgThumb.setImageResource(mThumbIds[position]);
        holder.ImhText.setText(mTexts[position]);                     
        return convertView;        
    } 

    private class ViewHolder {
       ImageView ImgThumb;
       TextView ImhText;
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.allsong, R.drawable.albums,
            R.drawable.artists, R.drawable.playlists,
            R.drawable.settings
    };
    private String [] mTexts={
    		"All Songs", "Albums","Artists","Playlists","Settings"
    };
}